package mm.controller;

import com.gargoylesoftware.htmlunit.StringWebResponse;
import com.gargoylesoftware.htmlunit.TopLevelWindow;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HTMLParser;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import mm.test.MockContext;
import mm.test.MockContextImpl;
import mm.test.MockRequest;
import mm.test.MockResponse;
import mm.test.MockSession;
import mm.util.LOG;
import junit.framework.TestCase;

public class MainJspTest extends TestCase {

	private static MockContext mockContext=null;
	private WebClient webClient;
	private TopLevelWindow dummyWindow;


	protected void setUp() throws Exception {
		super.setUp();
		if(mockContext==null)
			mockContext=new MockContextImpl("webapp");
		webClient = new WebClient();
		webClient.setJavaScriptEnabled(false);
		dummyWindow = new TopLevelWindow("", webClient);

	}
	
	public void testSimpleTest() throws Exception {
		MockSession mockSession = mockContext.createSession();
		MockRequest mockRequest=mockSession.createRequest();
		mockRequest.setServletPath("/");
		MockResponse mockResponse=mockRequest.submit();
		LOG.debug(mockResponse.getContent());
		StringWebResponse stringWebResponse = new StringWebResponse(mockResponse.getContent());
		HtmlPage page = HTMLParser.parse(stringWebResponse, dummyWindow);
		HtmlElement html = page.getDocumentElement();
		HtmlDivision div=(HtmlDivision) html.getHtmlElementsByTagName("div").get(0);
		LOG.debug(div.asText()); // luan ma?!
	}
}